<?php
$uid = $_SESSION['tcADMINID'];

if(isset($_POST['save_approval']))
{
	$businessname = $_POST['businessname'];
	$desc = $_POST['desc'];
	$openinghours = $_POST['openinghours'];
	$location = $_POST['location'];
	$listinglevel = $_POST['listinglevel'];
	$cat = $_POST['cat'];
	$url = $_POST['url'];
	$keywords = $_POST['keywords'];
	$imgpriority = $_POST['imgpriority'];
	$contactemail = $_POST['contactemail'];
	$showcontactemail = $_POST['showcontactemail'];
	$address1 = $_POST['address1'];
	$address2 = $_POST['address2'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$postcode = $_POST['postcode'];
	$phone = $_POST['phone'];
	$fax = $_POST['fax'];
	$businessdesc = $_POST['businessdesc'];
	$listinglevel = $_POST['listinglevel'];
	
	$catcount = count($cat);
	for($i=0;$i<$catcount;$i++)
	{
		if($category == "") $category = $cat[$i];
		else $category = $category.",".$cat[$i];
		
	}
	
	
	$tempimage1 = $_FILES['tempimage1']['name'];
	$tempimage2 = $_FILES['tempimage2']['name'];
	$tempimage3 = $_FILES['tempimage3']['name'];
	$tempimage4 = $_FILES['tempimage4']['name'];
	$tempimage5 = $_FILES['tempimage5']['name'];
	$tempimage6 = $_FILES['tempimage6']['name'];
	
	$logo = $_FILES['logo']['name'];
	
	if($listinglevel == 1)
	{
		$amount = 0;
		$duration = 0;
		
		$tempimage1 = "";
		$tempimage2 = "";
		$tempimage3 = "";
		$tempimage4 = "";
		$tempimage5 = "";
		$tempimage6 = "";
	}
	else
	{
		$amount = 10;
		$duration = 30;
	}
	

	$path = "../directoryimage/";
	$thumb_path = "../directoryimage/thumb/";
	$logopath = "../directoryimage/logo/";
	$imageformaterror = 0;
	
	if($_FILES['logo']['name'] != "")
	{	
	if($_FILES['logo']['type'] == "image/pjpeg" || $_FILES['logo']['type'] == "image/jpeg")
	{
		
			//move_uploaded_file($_FILES['tempimage1']['tmp_name'],$path.$tempimage1);
			$fname = $uid.'logo'.time();
			if($_FILES['logo']['type'] == "image/gif") $filetype = ".gif";
			else  $filetype = ".jpg";
			
			$newupload = $_FILES['logo']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			if($width > 220)
			{
				$newwidth=220;
				$w=$width/$newwidth;
				$newheight=$height/$w;
			}
			if($height > 175)
			{
				$newheight = 175;	
				$h = $height/$newheight;
				$newwidth = $width/$h;
			}
			if($width <= 220) $newwidth = $width;
			if($height <= 175) $newheight = $height;
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $logopath.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			/*//$path = $thumb_path;
			$newupload = $_FILES['logo']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			$newwidth=150;
				
				$w=$width/$newwidth;
				$newheight=$height/$w;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $thumb_path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);*/
			
			$logoname = $photo1;
	}
	else
	{
		$imageformaterror = 1;	
	}
}

if($tempimage1 != "")
{	
	if($_FILES['tempimage1']['type'] == "image/gif" || $_FILES['tempimage1']['type'] == "image/pjpeg" || $_FILES['tempimage1']['type'] == "image/jpeg")
	{
		
			//move_uploaded_file($_FILES['tempimage1']['tmp_name'],$path.$tempimage1);
			$fname = $uid.'tempimage1'.time();
			if($_FILES['tempimage1']['type'] == "image/gif") $filetype = ".gif";
			else  $filetype = ".jpg";
			
			$newupload = $_FILES['tempimage1']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			if($width > 800)
			{
				$newwidth=800;
				$w=$width/$newwidth;
				$newheight=$height/$w;
			}
			if($height > 600)
			{
				$newheight = 600;	
				$h = $height/$newheight;
				$newwidth = $width/$h;
			}
			if($width <= 800) $newwidth = $width;
			if($height <= 600) $newheight = $height;
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			//$path = $thumb_path;
			$newupload = $_FILES['tempimage1']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			$newwidth=150;
				
				$w=$width/$newwidth;
				$newheight=$height/$w;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $thumb_path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			$tempimage1 = $photo1;
	}
	else
	{
		$imageformaterror = 1;	
	}
}
if($tempimage2 != "")
{
	if($_FILES['tempimage2']['type'] == "image/gif" || $_FILES['tempimage2']['type'] == "image/pjpeg" || $_FILES['tempimage2']['type'] == "image/jpeg")
	{
		//move_uploaded_file($_FILES['tempimage2']['tmp_name'],$path.$tempimage2);
		if($_FILES['tempimage2']['type'] == "image/gif") $filetype = ".gif";
			else  $filetype = ".jpg";
			$fname = $uid.'tempimage2'.time();
			$newupload = $_FILES['tempimage2']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			if($width > 800)
			{
				$newwidth=800;
				$w=$width/$newwidth;
				$newheight=$height/$w;
			}
			if($height > 600)
			{
				$newheight = 600;	
				$h = $height/$newheight;
				$newwidth = $width/$h;
			}
			if($width <= 800) $newwidth = $width;
			if($height <= 600) $newheight = $height;
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			//$path = $thumb_path;
			$newupload = $_FILES['tempimage2']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			$newwidth=150;
				
				$w=$width/$newwidth;
				$newheight=$height/$w;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $thumb_path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			$tempimage2 = $photo1;
	}
	else
	{
		$imageformaterror = 1;	
	}
}
if($tempimage3 != "")
{
	if($_FILES['tempimage3']['type'] == "image/gif" || $_FILES['tempimage3']['type'] == "image/pjpeg" || $_FILES['tempimage3']['type'] == "image/jpeg")
	{
		//move_uploaded_file($_FILES['tempimage3']['tmp_name'],$path.$tempimage3);
		if($_FILES['tempimage3']['type'] == "image/gif") $filetype = ".gif";
			else  $filetype = ".jpg";
			$fname = $uid.'tempimage3'.time();
			$newupload = $_FILES['tempimage3']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			if($width > 800)
			{
				$newwidth=800;
				$w=$width/$newwidth;
				$newheight=$height/$w;
			}
			if($height > 600)
			{
				$newheight = 600;	
				$h = $height/$newheight;
				$newwidth = $width/$h;
			}
			if($width <= 800) $newwidth = $width;
			if($height <= 600) $newheight = $height;
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			//$path = $thumb_path;
			$newupload = $_FILES['tempimage3']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			$newwidth=150;
				
				$w=$width/$newwidth;
				$newheight=$height/$w;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $thumb_path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			$tempimage3 = $photo1;
	}
	else
	{
		$imageformaterror = 1;	
	}
}
if($tempimage4 != "")
{
	if($_FILES['tempimage4']['type'] == "image/gif" || $_FILES['tempimage4']['type'] == "image/pjpeg" || $_FILES['tempimage4']['type'] == "image/jpeg")
	{
		//move_uploaded_file($_FILES['tempimage4']['tmp_name'],$path.$tempimage4);
		if($_FILES['tempimage4']['type'] == "image/gif") $filetype = ".gif";
			else  $filetype = ".jpg";
			$fname = $uid.'tempimage4'.time();
			$newupload = $_FILES['tempimage1']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			if($width > 800)
			{
				$newwidth=800;
				$w=$width/$newwidth;
				$newheight=$height/$w;
			}
			if($height > 600)
			{
				$newheight = 600;	
				$h = $height/$newheight;
				$newwidth = $width/$h;
			}
			if($width <= 800) $newwidth = $width;
			if($height <= 600) $newheight = $height;
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			//$path = $thumb_path;
			$newupload = $_FILES['tempimage4']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			$newwidth=150;
				
				$w=$width/$newwidth;
				$newheight=$height/$w;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $thumb_path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			$tempimage4 = $photo1;
	}
	else
	{
		$imageformaterror = 1;	
	}
}
if($tempimage5 != "")
{
	if($_FILES['tempimage5']['type'] == "image/gif" || $_FILES['tempimage5']['type'] == "image/pjpeg" || $_FILES['tempimage5']['type'] == "image/jpeg")
	{
		//move_uploaded_file($_FILES['tempimage5']['tmp_name'],$path.$tempimage5);
		if($_FILES['tempimage5']['type'] == "image/gif") $filetype = ".gif";
			else  $filetype = ".jpg";
			$fname = $uid.'tempimage5'.time();
			$newupload = $_FILES['tempimage5']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			if($width > 800)
			{
				$newwidth=800;
				$w=$width/$newwidth;
				$newheight=$height/$w;
			}
			if($height > 600)
			{
				$newheight = 600;	
				$h = $height/$newheight;
				$newwidth = $width/$h;
			}
			if($width <= 800) $newwidth = $width;
			if($height <= 600) $newheight = $height;
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			//$path = $thumb_path;
			$newupload = $_FILES['tempimage5']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			$newwidth=150;
				
				$w=$width/$newwidth;
				$newheight=$height/$w;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $thumb_path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			$tempimage5 = $photo1;
	}
	else
	{
		$imageformaterror = 1;	
	}
}
if($tempimage6 != "")
{
	if($_FILES['tempimage6']['type'] == "image/gif" || $_FILES['tempimage6']['type'] == "image/pjpeg" || $_FILES['tempimage6']['type'] == "image/jpeg")
	{
		//move_uploaded_file($_FILES['tempimage6']['tmp_name'],$path.$tempimage6);
		if($_FILES['tempimage6']['type'] == "image/gif") $filetype = ".gif";
			else  $filetype = ".jpg";
			$fname = $uid.'tempimage6'.time();
			$newupload = $_FILES['tempimage6']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			if($width > 800)
			{
				$newwidth=800;
				$w=$width/$newwidth;
				$newheight=$height/$w;
			}
			if($height > 600)
			{
				$newheight = 600;	
				$h = $height/$newheight;
				$newwidth = $width/$h;
			}
			if($width <= 800) $newwidth = $width;
			if($height <= 600) $newheight = $height;
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			//$path = $thumb_path;
			$newupload = $_FILES['tempimage6']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			$newwidth=150;
				
				$w=$width/$newwidth;
				$newheight=$height/$w;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $thumb_path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			$tempimage6 = $photo1;
	}
	else
	{
		$imageformaterror = 1;	
	}
}

if($imageformaterror == 0)
{
	$cust = time();

	mysql_query("insert into directory (BusinessName, Description, OpeningHours, Location, ListingLevel, Category, URL, Logo, Keywords, ImgPriority, TemplateImage1, TemplateImage2, TemplateImage3, TemplateImage4, TemplateImage5, TemplateImage6, ContactEmail, ShowEmail, Address1, Address2, City, State, Postcode, Phone, Fax, BusinessDesc, Status, InsertedBy, InsertedDate, Amount, Duration, Cust) values('$businessname', '$desc', '$openinghours', '$location', '$listinglevel', '$category', '$url', '$logoname', '$keywords', '$imgpriority', '$tempimage1', '$tempimage2', '$tempimage3', '$tempimage4', '$tempimage5', '$tempimage6', '$contactemail', '$showcontactemail', '$address1', '$address2', '$city', '$state', '$postcode', '$phone', '$fax', '$businessdesc', 1, '$uid', now(), '$amount', '$duration', '$cust')");
	
	$lastinsertid = mysql_insert_id();
	
	$e = mysql_fetch_array(mysql_query("select * from users where Id='$uid'"));
			$email = "support@alicespringsonline.com";
			$from = "From: <$email>";
				$to = $TC_Email;
				$subject = "New Business Directory Listing submitted in alicespringsonline.com";
				$message = "
Hello,

A new business directory listing ".$businessname." has been submitted at alicespringsonline.com

Submited By:".$e['FirstName']." ".$e['LastName']."

Please click on link below to login and approve picture. 

http://alicespringsonline.com/tcadmin/

";
		mail($to, $subject, $message, $from);
		
	//to paypal
	
	if($listinglevel == 1)
	{
		
		$e = mysql_fetch_array(mysql_query("select * from users where Id='$uid'"));
		$email = $e["Email"];
		$from = "From: <$email>";
			$to = $TC_Email;
			$subject = "New Business Directory Listing submitted in alicespringsonline.com";
			$message = "
Hello,

A new business directory listing ".$businessname." has been submitted at alicespringsonline.com

Submited By:".$e['FirstName']." ".$e['LastName']."

Please click on link below to login and approve picture. 

http://alicespringsonline.com/tcadmin/

";
		mail($to, $subject, $message, $from);
		
		//header("location:index.php?tc=listing_add&_s=T&_s=1");
		echo "<script>window.location='index.php?tc=listing_add&_s=T&_s=1'</script>";
		exit;
	}
	?>
    
   <?php /*?> <form method="post" action="paypal_dir/process.php" name="credits">
        <input type="hidden" name="userid" value="<?php echo $uid;?>">
        <input type="hidden" name="custom_field" value="<?php echo $uid;?>">
        <input type="hidden" name="invoice" value="<?php echo $lastinsertid;?>">
        <input type="hidden" name="amount" value="<?php echo number_format($amount,2);?>">
        <input type="hidden" name="item_name" value="TENNANTCREEKONLINE.com">
        <div style="display:none">
        <input type="submit" />
        </div>
    </form>
    <script language="javascript" type="text/javascript">
		document.credits.submit();
	</script><?php */?>
    
    
<?php 
}
else
{
	//header("location:index.php?tc=listing_add&_s=T&_e=1");
	echo "<script>window.location='index.php?tc=listing_add&_s=T&_e=1'</script>";
}

}
?>